@extends('develop.layoutEdit')

@section('css')
    <style>
        .layer-go-back{
            display:none;
        }
    </style>
@endsection


@section('title')
    <li class="cur">
        <span>积分设置</span>
    </li>
@endsection

@section('content')

    <input type="hidden" name="function_id" id="function_id" value="{{ $function_id or ''}}">

    <div class="form-group">
        <label class="col-sm-4 control-label" ><span class="red pr5">*</span> 展示名称：</label>
        <div class="col-sm-3">
            <input type="text" placeholder="展示名称"  name="show_name" id="show_name"  class="form-control" value="{{$configure['show_name'] or ''}}">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-4 control-label"><span class="red pr5">*</span> 赠送积分依据：</label>
        <div class="col-sm-6">
            <div class="layui-form">
                <input type="radio" name="points_according"  lay-filter="filter" value="1"  class="is_open" title="商品基础资料赠送积分" @if( isset($configure['points_according']) && $configure['points_according'] == 1) checked @endif>
                <input type="radio" name="points_according"  lay-filter="filter" value="2"  class="is_open" title="订单成交金额赠送积分" @if( isset($configure['points_according']) && $configure['points_according'] == 2) checked @endif>
            </div>
        </div>
    </div>


    <div class="form-group" @if( isset($configure['points_according']) && $configure['points_according'] == 1 )  style="display: none;" @endif id="points">
        <label  class="col-sm-4 control-label" for="order_turnover"><span class="red pr5">*</span> 赠送比例：</label>
        <div  class="col-sm-3">
            <span >订单成交金额  :</span> <input type="text" placeholder="赠送比例"  name="order_turnover" id="order_turnover"  style="width: 80px;display:inline-block;" class="form-control" value="{{$configure['order_turnover'] or ''}}">
        </div>

        <div  class="col-sm-3" style="margin-left: -80px;">
            <span>赠送积分 :</span> <input type="text" placeholder="赠送积分"  name="give_points" id="give_points"  style="width: 80px;display:inline-block;" class="form-control" value="{{$configure['give_points'] or ''}}">
        </div>

    </div>

    <div class="form-group">
        <label class="col-sm-4 control-label" ><span class="red pr5">*</span> 积分兑换比例：</label>
        <div class="col-sm-2">
            <input type="text" placeholder="积分兑换比例"  name="points_exchange_ratio" id="points_exchange_ratio"  class="form-control" value="{{$configure['points_exchange_ratio'] or ''}}">
            <span class="help-block">分=1元</span>
        </div>
    </div>


    <div class="form-group">
        <label class="col-sm-4 control-label"><span class="red pr5">*</span> 积分支付单笔订单应付金额最大占比：</label>
        <div class="col-sm-2">
            <input type="text" placeholder="积分支付单笔订单应付金额最大占比"  name="points_payable_ration" id="points_payable_ration"  class="form-control" value="{{$configure['points_payable_ration'] or ''}}">
            <span class="help-block">如：设置了50%，应支付金额￥20，积分最大支付金额￥10</span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-4 control-label"><span class="red pr5">*</span> 积分说明：</label>
        <div class="col-sm-3">
            <textarea placeholder="积分说明"  id="points_description" name="points_description" rows="3" class="form-control">{{$configure['points_description'] or ''}}</textarea>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-4 control-label"></label>
        <div class="col-sm-5">
            <input type="button"  value="保存" onclick="func.edit();" class="btn btn-success">
        </div>
    </div>

@endsection

@section('js')
<script>
    layui.use(['form'], function() {
        var form = layui.form();

        //监听单选框
        form.on('radio(filter)',function(data){
            if ( data.value == 1 ) {
                $('#points').hide();
            } else {
                $('#points').show();
            }

        });

    });

    var func = {

        function_id : {{ $function_id or ''}},

        //保存
        edit:function(){

            //表单数据
            var show_name =$('#show_name').val();
            var points_according = $('input[name="points_according"]:checked').val();
            var order_turnover =$('#order_turnover').val();
            var give_points =$('#give_points').val();
            var points_exchange_ratio =$('#points_exchange_ratio').val();
            var points_payable_ration =$('#points_payable_ration').val();
            var points_description = $('#points_description').val();
            var points_change_pic =$('#points_change_pic').val();
            var function_id =$('#function_id').val();

            var configure ={ };

            configure.function_id = function_id;

            if (points_according == 2) {
                configure.order_turnover =order_turnover;
                configure.give_points =give_points;
            }
            configure.show_name =show_name;
            configure.points_according =points_according;

            configure.points_exchange_ratio =points_exchange_ratio;
            configure.points_payable_ration =points_payable_ration;
            configure.points_description =points_description;
            configure.points_payable_ration =points_payable_ration;
            configure.points_change_pic =points_change_pic;


            var msg ='';

            if(E.isEmpty(show_name)){
                msg +='请输入展示名称</br>';
            }

            if(E.isEmpty(points_according)){
                msg +='请选择赠送积分依据</br>';
            }else if(points_according == 2){
                if(!E.isDigital(order_turnover)){
                    msg +='请输入正确的订单成交金额</br>';
                }

                if(!E.isDigital(give_points)){
                    msg +='请输入正确的赠送积分</br>';
                }
            }

            if(!E.isDigital(points_exchange_ratio)){
                msg +='请输入正确的积分兑换比例</br>';
            }

            if(!E.isDigital(points_payable_ration)){
                msg +='请输入正确的积分支付单笔订单应付金额最大占比</br>';
            }

            if(E.isEmpty(points_description)){
                msg +='请输入积分说明</br>';
            }

            if(msg){
                layer.alert( msg , { icon: 2 } ) ;
                return false;
            }

            var index  = layer.load() ;
            E.ajax( {
                type:'get',
                url: '/lar/develop/function/store/'+func.function_id,
                data:configure,
                dataType:'json',
                success: function ( obj ){

                    layer.close( index) ;

                    if ( obj.code == 200 ) {
                        layer.alert( obj.message , { icon: 1,time : 1500 } ) ;
                    } else {
                        layer.alert( obj.message , { icon: 2 } ) ;
                    }
                }
            } ) ;

        }

    }

</script>

@endsection